home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / errors.frm < prev    next >
Text File  |  1995-07-04  |  2KB  |  58 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   4230
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   6720
  8.    Height          =   4635
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4230
  12.    ScaleWidth      =   6720
  13.    Top             =   1170
  14.    Width           =   6840
  15. End
  16. Attribute VB_Name = "Form1"
  17. Attribute VB_Creatable = False
  18. Attribute VB_Exposed = False
  19. Option Explicit
  20.  
  21.  
  22. Private Sub Form_Load()
  23.     Dim db As DATABASE
  24.     Dim dbName As String
  25.     Dim rs As Recordset
  26.     Dim s As String
  27.  
  28.     On Error GoTo LoadError
  29.  
  30.   ' Get the database name and open the database.
  31.     dbName = BiblioPath()       ' BiblioPath is a function in READINI.BAS
  32. 10  Set db = DBEngine.Workspaces(0).OpenDatabase(dbName)
  33.     
  34.     ' This statement will cause an error, because there's no such table
  35.     ' as No Such Table.
  36. 20  Set rs = db.OpenRecordset("No Such Table", dbOpenTable)
  37.  
  38.     ' There is a table named Titles, so this one should work.
  39. 30  Set rs = db.OpenRecordset("Titles", dbOpenTable)
  40.  
  41.     ' There's no such field as No Such Field, so here's another error.
  42. 40  s = rs![No Such Field]
  43.  
  44.     ' This causes an error because Year Published only takes numeric values.
  45. 50  rs![Year Published] = "XYZ"
  46.  
  47.     ' Finally!
  48. 60  End
  49.  
  50. Exit Sub
  51.  
  52. LoadError:
  53.     MsgBox "Error #" & Str$(Err.Number) & " at Line " & Str$(Erl) & " - " & Err.Description & " - reported by " & Err.Source
  54. Resume Next
  55.  
  56. End Sub
  57.  
  58.